package com.mmall.admin.shiro;


/**
 * 当前用户各种变量获取和操作
 *
 * @author danbin
 */
public class ShiroOperation {

    public static final ThreadLocal<ShiroUser> THREAD_LOCAL = new ThreadLocal<>();


    /**
     * 获取当前管理员角色ID
     */
    public static String getCurrentRoleId() {
        ShiroUser shiroUser = THREAD_LOCAL.get();
        shiroUser = DevTool.getCurrentAdmin(shiroUser);
        if (shiroUser == null) {
            return null;
        }
        return shiroUser.getRoleIds();
    }

    /**
     * 获取当前管理员名
     */
    public static String getCurrentName() {
        ShiroUser shiroUser = THREAD_LOCAL.get();
        shiroUser = DevTool.getCurrentAdmin(shiroUser);
        if (shiroUser == null) {
            return null;
        }
        return shiroUser.getUsername();
    }

    /**
     * 获取当前管理员
     */
    public static ShiroUser getCurrentAdmin() {
        ShiroUser shiroUser = THREAD_LOCAL.get();
        shiroUser = DevTool.getCurrentAdmin(shiroUser);
        return shiroUser;
    }


    public static void remove(){
        THREAD_LOCAL.remove();
    }
}
